home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17023 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: int (*p)[4]; (Watcom problem)
  5. Date: Fri, 12 Apr 1996 18:17:45 GMT
  6. Organization: Netcom
  7. Message-ID: <316e9d18.157768629@nntp.ix.netcom.com>
  8. References: <4kcd03$37j@morgoth.sfu.ca>
  9. NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 12  1:15:51 PM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. mpohores@news.sfu.ca (Michael John Pohoreski) wrote:
  14.  
  15. > I came across (ARM, page 97) the following way to define
  16. > a pointer to an array:
  17. >    int (*p)[];
  18. > (Yes, I allready know I can just do: int *p)
  19. > So I tried it in a small C++ test program: p2a.cpp
  20. > #include <stdio.h>
  21. > void main( void )
  22. > {
  23. >   int a[4] = { -13, 11, -7, 5 };
  24. >   int (*x)[4]; // pointer to array
  25. >   for (int i = 0; i < 4; i++ )
  26. >   {
  27. >     (int *)x = &a[i];
  28. >     printf( "%d\n", (*x)[0] );
  29. >   }
  30. > }
  31. > Now here's my problem:
  32. >  Under Watcom 10.5, the above doesn't compile with wcl386
  33. > but it compiles under DJGPP 2.0, and Borland C++ 3.1  Anyone know why?
  34. >  Is this a bug?
  35.  
  36. Watcom is correct.  I don't know about DJGPP, but in Borland C++ this
  37. is an extension to the language.  Version 5.0 correctly rejects this
  38. if the -A switch is used.
  39.  
  40. The problem is that (int *)x is not an lvalue and may not appear as
  41. the left operand of assignment.
  42.  
  43. Why not use the correct syntax?
  44.  
  45.     x = &a;
  46.  
  47.  
  48. Michael M Rubenstein
  49.